package com.sxt.bus.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sxt.bus.service.CustomerService;
import com.sxt.bus.service.TjfxService;
import com.sxt.bus.vo.TjfxVo;
import com.sxt.bus.vo.tjfx.BaseEntity;
import com.sxt.bus.vo.tjfx.LineEntity;
import com.sxt.bus.vo.tjfx.Pie;

@Controller
@RequestMapping("tjfx")
public class TjfxController {
	@Autowired
	private CustomerService customerService;
     
	@Autowired
	private TjfxService tjfxService;

	//数据统计
			@RequestMapping("toCustomerArea")
			public String toCustomerArea(){
				return "tjfx/tjfxManager";
				//查询客户数据
			
			}
			
			
			@RequestMapping("customersAddressPie")
			@ResponseBody
			public List<Pie> customersAddressPie(){
				return customerService.queryCustomerAddressCount();	
			}
			
	//统计客户性别
			@RequestMapping("toCustomerSex")
			public String toCustomerSex(){
				return "tjfx/sexManager";
				//查询客户数据
			
			}
			
			
			@RequestMapping("customerSex")
			@ResponseBody
			public List<Pie> customerSex(){
				return customerService.queryCustomerSex();	
			}
			/**
			 * 跳转到业务员年度销售额柱子图
			 */
			@RequestMapping("toTjOpernameSalMoneyYear")
			public String toTjOpernameSalMoneyYear(){
				return "tjfx/tjOpernameSalMoneyYear";
			}
			
			/**
			 * 查询业务员年度销售额柱子图的数据
			 */
			@RequestMapping("tjOpernameSalMoneyYear")
			@ResponseBody
			public Map<String,Object> tjOpernameSalMoneyYear(TjfxVo vo){
				List<BaseEntity>  list=this.tjfxService.queryOpernameSalMoneyYear(vo.getYear());
				Map<String,Object> map=new HashMap<String, Object>();
				List<String> names=new ArrayList<>();
				List<Double> values=new ArrayList<>();
				for (BaseEntity e : list) {
					names.add(e.getName());
					values.add(e.getValue());
				}
				map.put("names", names);
				map.put("values", values);
				return map;
			}
			
			/**
			 * 跳转到
			 * 公司年度月份销售额曲线图
			 */
			@RequestMapping("toTjYearMonthLine")
			public String toTjYearMonthLine(){
				return "tjfx/tjYearMonthLine";
			}
			/**
			 * 查询
			 * 公司年度月份销售额曲线图的数据
			 */
			@RequestMapping("tjYearMonthLine")
			@ResponseBody
			public List<Double> tjYearMonthLine(TjfxVo tjfxVo){
				List<Double>  doubles=new ArrayList<>();
				LineEntity lineEntity=this.tjfxService.queryTjYearMonthLine(tjfxVo.getYear());
				if(null!=lineEntity){
					doubles.add(lineEntity.getP1()==null?0:lineEntity.getP1());
					doubles.add(lineEntity.getP2()==null?0:lineEntity.getP2());
					doubles.add(lineEntity.getP3()==null?0:lineEntity.getP3());
					doubles.add(lineEntity.getP4()==null?0:lineEntity.getP4());
					doubles.add(lineEntity.getP5()==null?0:lineEntity.getP5());
					doubles.add(lineEntity.getP6()==null?0:lineEntity.getP6());
					doubles.add(lineEntity.getP7()==null?0:lineEntity.getP7());
					doubles.add(lineEntity.getP8()==null?0:lineEntity.getP8());
					doubles.add(lineEntity.getP9()==null?0:lineEntity.getP9());
					doubles.add(lineEntity.getP10()==null?0:lineEntity.getP10());
					doubles.add(lineEntity.getP11()==null?0:lineEntity.getP11());
					doubles.add(lineEntity.getP12()==null?0:lineEntity.getP12());
				}
				return doubles;
			}		
			
}
